import React from 'react';
import track from 'utils/track';
import { navigateOpen } from 'utils/router';
import './index.scss';
import intl from '../../../locale';

const { orgId } = window.UILessConfig;
const nextUrl = encodeURIComponent(`${location.origin}?org_id=${orgId}`);
const url = `https://devops.aliyun.com/org-admin/${orgId}/members/member?invite=true&next_url=${nextUrl}`;

const Invite = () => {
  const onClick = () => {
    track({ action: 'invite from topbar', page: 'top bar' });
    navigateOpen(url);
  };
  return (
    <div className="navigation-invite" onClick={onClick}>
      {intl.get({ id: 'code-assets.initNavigation.invite.Invitation', defaultMessage: '邀请' })}
    </div>
  );
};

const getInvite = () => ({
  element: <Invite />,
  trigger: '',
  action: 'custom',
});

const registerInvite = () => {
  window.TB_NAVIGATION.CustomInvite.register(getInvite());
};

export default registerInvite;
